<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="zh-cn">
    <head>
        <!-- Bootstrap -->
        <include file="Include/css" />
        <title>中经汇通</title>
        <!--编辑器--->
        <link type="text/css"  rel="stylesheet" href="__STATICS__/js/um/themes/default/css/umeditor.css" >
        <link href="__STATICS__/css/admin/index.css" rel="stylesheet">
        <link href="__STATICS__/css/sweet-alert.css" rel="stylesheet">
        <script type="text/javascript" src="__STATICS__/js/sweet-alert.min.js"></script>
    </head>

    <body>
        <include file="Include/nav_top" />
        <div class="container clearfix" id="left_menu_wraper" >
            <include  file="Include/menu_left" />
            <div id="right-content">
                <div id="right-content-inner">
                    <ul class="breadcrumb">
                        <span>您的位置：</span>
                        <li><a href="{:U('Houtai/Index/index')}">首页</a> </li>
                        <li class="">消息管理</li>
                        <li class="active">消息列表</li>
                    </ul>
                    <p>
                        <button id="add_look" class="btn btn-orange" type="button" data-id="2" >
                            添加消息
                        </button>
                    </p>
                    <div role="tabpanel">

                        <div class="row clearfix margin10 form-horizontal">
                                    <form  name="query" method="POST" >
                                        <span class="pull-left ml30 form_bar">搜索条件：</span>
                                        <div class="col-md-2">
                                            <input type="text" name="sTitle" value="{$Think.request.sTitle}" placeholder=" 标题" class="pull-left ml10 form-control" />
                                        </div>
                                        <div class="col-md-2">
                                            <select  name="sIsSend" class="pull-left ml10 form-control" >
                                                <option value="-1" <eq name="Think.request.sIsSend" value="-1" > selected </eq> >-发送状态-</option>
                                                <option value="1" <eq name="Think.request.sIsSend" value="1" > selected </eq> >已发送</option>
                                                <option value="0" <eq name="Think.request.sIsSend" value="0" > selected </eq> >未发送</option>
                                            </select>
                                        </div>
                                        <div class="col-md-2">
                                            <select  name="sType" class="pull-left ml10 form-control" >
                                                <option value="-1" <eq name="Think.request.sType" value="-1" > selected </eq> >-类型-</option>
                                                <option value="1" <eq name="Think.request.sType" value="1" > selected </eq> >系统消息</option>
                                                <option value="2" <eq name="Think.request.sType" value="2" > selected </eq> >优惠信息</option>
                                                <option value="3" <eq name="Think.request.sType" value="3" > selected </eq> >活动信息</option>
												<option value="4" <eq name="Think.request.sType" value="4" > selected </eq> >银行专区信息</option>
												<option value="5" <eq name="Think.request.sType" value="5" > selected </eq> >电信运营商信息</option>
                                            </select>
                                        </div>
                                        <button type="submit" class="pull-left btn btn-default ml20">
                                            搜索
                                        </button>
                                    </form>
                                    
                                </div>

                                <table class="table ">
                                    <thead class="table_head">
                                        <tr class="border">
                                            <th>编号</th>
                                            <th>标题</th>
                                            <th>作者</th>
                                            <th>作者来源</th>
                                            <th>消息类型</th>
                                            <th>发送状态</th>
                                            <th>添加时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <volist name="list" id="vo">
                                            <tr class="qr_tar">
                                                <td>
                                                    {$i+$num}
                                                </td>
                                                <td>
                                                   {$vo.title} 
                                                </td>
                                                <td>{$vo.author} </td>
                                                <td>{$vo['authorFrom'] == 1 ? '商家':'管理员'} </td>
                                                <td>
                                                	<switch name='vo.messageType'>
	                                                	<case value='1'>系统消息</case>
	                                                	<case value='2'>优惠信息</case>
	                                                	<case value='3'>活动消息</case>
														<case value='4'>银行专区消息</case>
														<case value='5'>电信运营商消息</case>
                                                	</switch>
                                               	</td>
                                                <td>{$vo['isSend'] == 1 ? '已发送':'未发送'} </td>
                                                <td>{$vo['addTime'] | date="Y/m/d H:i:s",###} </td>
                                                <td data-id="{$vo.messageID}" >
                                                    <a href="javascript:void(0);" class="edit_look" >编辑</a>
                                                    /
                                                    <a href="javascript:void(0);" class="tar_delete" >删除</a> 
                                                </td>
                                            </tr>
                                        </volist>
                                    </tbody>
                                </table>

                                <div class="clearfix s_page pull-right">
                                    {$page}
                                </div>
                            </div>

                    </div>

                </div>

            </div>
        
        <!-- 基本信息 Modal - 开始 -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel"> </h4>
                    </div>
                    <div class="modal-body">
                        <div role="tabpanel" class="tab-pane active" id="home">

                            <div class="row clearfix">
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                                    标题：
                                    </div>
                                    <div class="col-md-7">
                                            <input id="title" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    * 建议100字内
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                                    是否发送：
                                    </div>
                                    <div class="col-md-7">
                                        <div class="btn-group clearfix" data-toggle="buttons">
                                            <label class="btn btn-warning ">
                                                <input name="isSend" type="radio" autocomplete="off" value="1"> ON
                                            </label>
                                            <label class="btn btn-warning ">
                                                <input name="isSend" type="radio" autocomplete="off" value="0"> OFF
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    * 默认不发送
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                               类型：
                                    </div>
                                    <div class="col-md-7">
                                        <label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio1" value="1" checked> 系统消息
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio2" value="2"> 优惠信息
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio2" value="3"> 活动信息
                                        </label>
										<label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio2" value="4"> 银行专区信息
                                        </label>
										<label class="radio-inline">
                                            <input type="radio" name="type" id="inlineRadio2" value="5"> 电信运营商信息
                                        </label>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    *
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        封面1：
                                    </div>
                                    <div class="col-md-7">
                                        <div class="upload_wraper dash clearfix" style="width:200px;height:200px;">
                                            <img src="__STATICS__/images/upload_comn.png" class=" col-xs-12" id="pic" alt=""/>
                                            <input type="file" class="input_file" id="fileupload" name="file" value="" data-url="" multiple=""/>
                                        </div>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        *系统消息可空
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        封面2：
                                    </div>
                                    <div class="col-md-7">
                                        <div class="upload_wraper dash clearfix" style="width:200px;height:200px;">
                                            <img src="__STATICS__/images/upload_comn.png" class=" col-xs-12" id="pic2" alt=""/>
                                            <input type="file" class="input_file" id="fileupload2" name="file" value="" data-url="" multiple=""/>
                                        </div>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        *封面2暂不使用，留待拓展
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                                    分类：
                                    </div>
                                    <div class="col-md-7">
                                            <input id="categoryID" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    * 填写分类ID，分类ID对应常用设置中的分类的编号，用于筛选，请先设置正确分类再添加消息。
                                    </div>
                                </div>
								<div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                                    地区：
                                    </div>
                                    <div class="col-md-7">
                                            <input id="regiontext" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    * 填写地区ID，多地区请用英文半角逗号分隔开。地区ID对应常用设置中的地区的编号，请先设置正确地区再添加消息。
                                    </div>
                                </div>
								
								<div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                                    简介：
                                    </div>
                                    <div class="col-md-7">
                                            <input id="intro" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    * 活动简介
                                    </div>
                                </div>
								
								<div class="col-md-12 margin10 people">
                                    <div class="col-md-2 text_right form_bar">
                                                    参加人数：
                                    </div>
                                    <div class="col-md-7">
                                            <input id="people" type="text" class="form-control" value="0"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    * 默认为0
                                    </div>
                                </div>
								
                                <div class="col-md-12 margin10">
			                            <div class="col-md-2 text_right form_bar">
			                                    	跳转类型：
			                            </div>
			                            <div class="col-md-6">
										<select name="" id="jumpType" class="form-control">
											<option value="no">无跳转</option>
											<option value="url">跳转至链接</option>
											<option value="goods">跳转至商品</option>
											<option value="shop">跳转至商家</option>
											<!--<option value="article">跳转至文章</option>-->
											<option value="material">跳转至素材</option>
			                            </select>
			                            </div>
			                            <div class="col-md-1 text_warning text_left form_bar">
			                                    *
			                            </div>
			                    </div>


                                
                                <div class="col-md-12 margin10" id="typevalue">
                                    <div class="col-md-2 text_right form_bar">
                                        
                                    </div>
                                    <div class="col-md-7">
                                        <input id="modalLink" type="text" class="form-control" placeholder=""/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        	*
                                    </div>
                                </div>

                                <div class="col-md-12 margin10" id="typevalue">
                                    <div class="col-md-2 text_right form_bar">
                                        排序
                                    </div>
                                    <div class="col-md-7">
                                        <input id="addIndex" type="text" class="form-control" placeholder="输入排序号"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        *号码越小排越前(可空,默认按时间排序)
                                    </div>
                                </div>

                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        是否首页显示：
                                    </div>
                                    <div class="col-md-7">
                                        <label class="radio-inline">
                                            <input type="radio" name="isShow" id="isShow1" value="0" checked> 否
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="isShow" id="isShow1" value="1"> 是
                                        </label>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        *
                                    </div>
                                </div>
                                
                                <div class="col-md-12 margin10 hide" id="addContent" >
                                    <div class="col-md-2 text_right form_bar">
                                                    正文：
                                    </div>
                                    <div class="col-md-10">
                                        <textarea id="content" ></textarea>
                                    </div>
                                </div>
                            </div>
                                    <input type="hidden" id="messageID" />
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="save" >保存</button>
                    </div>
                </div>
            </div>
        </div><!-- 基本信息 Modal - 结束 -->
        
        <include file="Include/script" />
        <script src="__STATICS__/js/bootstrap-editable.min.js"></script>
        
        <!--编辑器-->
        <script type="text/javascript" charset="utf-8" src="__STATICS__/js/um/umeditor.config.js"></script>
        <script type="text/javascript" charset="utf-8" src="__STATICS__/js/um/umeditor.min.js"></script>
        <script type="text/javascript" src="__STATICS__/js/jquery.ui.widget.js"></script>
        <script type="text/javascript" src="__STATICS__/js//jquery.iframe-transport.js"></script>
        <script type="text/javascript" src="__STATICS__/js/jquery.fileupload.js"></script>
        <script type="text/javascript" src="__STATICS__/js/jquery-form.js"></script>
        <script type="text/javascript" src="__STATICS__/js/upload_base.js"></script>
        <script type="text/javascript" src="__STATICS__/js/um/lang/zh-cn/zh-cn.js"></script>
                
       <script>
            var isReload = false; // 标识弹出框关闭之后是否刷新页面
            var myDom; // 当前操作的dom对象
            var img_url="__STATICS__/images";
            var um = UM.getEditor('content',{ initialFrameWidth:'100%' });
            var headImgUrl = "{:U('CNEPAdmin/Upload/uploadImg/pathType/5')}";
            /*菜单展开及高亮*/
            $(function () {
                $('.message').addClass('open');
                $('#message1').addClass('active');

                /*基本信息的弹出框隐藏后*/
                $('#myModal').on('hidden.bs.modal', function (e) {
                     reset_display();
                });
                
                /*编辑*/
                $(".edit_look").on("click", function () {
                    var self = $(this);
                    var messageID = self.closest("td").attr("data-id");
// um.setContent(arr.content);
                    var ajaxData = {};
                    ajaxData.messageID = messageID;
                    ajax_go_1(ajaxData,"{:U('CNEPAdmin/Message/messageMsg')}",onEdit);
                    
                });
                
                function onEdit(rsp) {
                    if(rsp.result > 0) {
                        var arr = rsp.arr;
                        $("#title").val(arr.title);
						
						$("#categoryID").val(arr.categoryID);
						$("#regiontext").val(arr.regiontext);
						$("#intro").val(arr.intro);
						$("#people").val(arr.people);
						
                        $("#messageID").val(arr.messageID);
                        $(":radio[name='isSend']").each(function(){
                            if($(this).val() == arr.isSend) $(this).click();
                        });
                        $("#pic").attr('src',arr.img);
                        $("#pic2").attr('src',arr.img2);
                        $(':radio[name="type"]').prop("checked",false);
                         $(':radio[name="type"][value="'+arr.messageType+'"]').prop("checked",true);
                        $(':radio[name="isShow"]').prop("checked",false);
                        $(':radio[name="isShow"][value="'+arr.isShow+'"]').prop("checked",true);
                        $("#myModalLabel").html("编辑(添加时间:"+ arr.addTime +")");

                        $("#jumpType").val(arr.jumpType);
                        /*if(arr.messageType==1){
                            $("#jumpType").val('article').trigger('change').attr('disabled','disabled');
                        }
                        else{
                            $("#jumpType").trigger('change').removeAttr('disabled');
                        }*/

                        if(arr.jumpType=='article'){
							$('#typevalue').hide();
							$("#addContent").removeClass('hide').show();
                            um.setContent(arr.content);
                        }
                        else if(arr.jumpType=='url'){
                            $("#modalLink").val(arr.url);
                        }else if(arr.jumpType=='shop'){
                            $("#modalLink").val(arr.shopID);
                        }else if(arr.jumpType=='goods'){
                            $("#modalLink").val(arr.goodsID);
                        }else if(arr.jumpType=='material'){
                            $("#modalLink").val(arr.materialID);
                        }

                        $("#addIndex").val(arr.index);

                        $('#myModal').modal(); // 跳出弹窗
                    } else {
                        swal("操作失败;" + rsp.desc,"","error");
                    }
                }
                
                /*删除弹窗*/
                $(".tar_delete").on("click", function () {
                    var self = $(this);
                    swal({   title: "您确定吗?",
                                text: "您将删除此此消息，用户将不再可见！",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "是的，删除",
                                cancelButtonText: "放弃",
                                closeOnConfirm: false
                            },
                            function (isConfirm) {
                                if (isConfirm) {
                                    var ajaxData = {};
                                    ajaxData.messageID = self.closest('td').attr('data-id');
                                    ajax_go_1(ajaxData ,'deleteMessage', onDel); // 参数1：提交的json数据；参数2:请求的地址；参数3：回调方法
                                }

                            });
                });
                /* rsp 即服务端返回的json */
                function onDel(rsp) {
                    if(rsp.result > 0) {
                        window.location.reload();
                    } else {
                        swal("操作失败",'',"error");
                    }
                }

                /*$('[name="type"]').on("change",function(){

                    if($(this).val()==1){
                        $("#jumpType").val('article').trigger('change').attr('disabled','disabled');
                    }
                    else{
                        $("#jumpType").removeAttr('disabled');
                    }


                });*/

                $('#jumpType').on("change",function(){
                    um.setContent("");
                    $('#modalLink').val('');

                    if($(this).val()=='article'){
                        $('#typevalue').hide();
                        $("#addContent").removeClass('hide').show();
                    }
                    else if($(this).val()=='no'){
                        $('#typevalue').hide();
                        $("#addContent").hide();
                    }else if($(this).val()=='url'){
                        $('#modalLink').attr('placeholder','输入url');
                        $('#typevalue').show();
                        $("#addContent").hide();
                    }else if($(this).val()=='shop'){
                        $('#modalLink').attr('placeholder','输入商店ID');
                        $('#typevalue').show();
                        $("#addContent").hide();
                    }else if($(this).val()=='goods'){
                        $('#modalLink').attr('placeholder','输入商品ID');
                        $('#typevalue').show();
                        $("#addContent").hide();
                    }else if($(this).val()=='material'){
                        $('#modalLink').attr('placeholder','输入素材ID');
                        $('#typevalue').show();
                        $("#addContent").hide();
                    }
					
                });


                /*添加时候弹窗*/
                $("#add_look").on("click", function() {
                    $("#myModalLabel").html("发布消息");
                    $('[name="type"][value="1"]').prop('checked','checked').trigger('change');
                    $('#myModal').modal(); // 跳出弹窗
                });
                
                /*点击保存*/
                $("#save").on("click", function () {
                    var rt = true;
                                        
                    var title = $.trim($("#title").val());
                    var messageID = $.trim($("#messageID").val());
                    var isSend =   $(":radio[name='isSend']:checked").val();
                    var content = um.getContent();
                    var type = $('input[name="type"]:checked').val();
                    var path = $('#pic').attr('src');
                    var path2 = $('#pic2').attr('src');
                    var isShow = $('input[name="isShow"]:checked').val();

                    var jumpType=$('#jumpType').val();
                    var addIndex=$('#jumpType').val();
                    var link = $('#modalLink').val();
                    var index=parseInt($('#addIndex').val());
					
					var categoryID = parseInt($('#categoryID').val());
					var regiontext = $.trim($('#regiontext').val());
					var intro = $.trim($('#intro').val());
					var people = parseInt($('#people').val());

                    if(title === '')
                    {   
                        rt = false;
                        $('#taskName').focus();
                        swal('请为消息拟好标题','','warning');
                    }
                    else if(index!=''&&isNaN(index)){
                        rt = false;
                        $('#addIndex').focus();
                        swal('排序号必须填写数字','','warning');
                    }
					else if(categoryID!=''&&isNaN(categoryID)){
                        rt = false;
                        $('#categoryID').focus();
                        swal('分类号必须填写数字','','warning');
                    }
					else if(people!=''&&isNaN(people)){
                        rt = false;
                        $('#people').focus();
                        swal('参加人数必须填写数字','','warning');
                    }

                    if(isSend == 'undefined')
                    {
                        ajaxData.isSend = 0;
                    }
                    
                    if(rt) {
                        var ajaxData ={}; // json 类

                        ajaxData.title = title;
                        ajaxData.isSend = isSend;
                        ajaxData.index = index;
                        ajaxData.isShow = isShow;
						ajaxData.categoryID = categoryID;
						ajaxData.regiontext = regiontext;
						ajaxData.intro = intro;
						ajaxData.people = people;

                        /*类型*/
                        ajaxData.messageType = type;
                        if(path!='/statics/images/upload_comn.png'){
                        	ajaxData.img = path;
                        }
                        
                        if(path2!='/statics/images/upload_comn.png'){
                        	ajaxData.img2 = path2;
                        }

                        ajaxData.jumpType = jumpType;

                        if(jumpType=='article'){
                            ajaxData.content = content;
                        }
                        else if(jumpType=='shop'){
                            ajaxData.shopID = link;
                        }
                        else if(jumpType=='goods'){
                            ajaxData.goodsID = link;
                        }
                        else if(jumpType=='url'){
                            ajaxData.url = link;
                        }
						else if(jumpType=='material'){
                            ajaxData.materialID = link;
                        }

                        if(messageID > 0)
                            ajaxData.messageID = messageID;
                        
                        console.log(ajaxData);
                        //return;
                         ajax_go_1(ajaxData ,"{:U('CNEPAdmin/Message/saveMessage')}",onSave);
                    } else {
                        return rt;
                    }
                    
                });
                
                function onSave(rsp) {
                    if(rsp.result > 0) {
                        swal("操作成功","","success");
                        window.location.reload();
                    } else {
                        swal("操作失败;"+rsp.desc,"","error");
                    }
                }
                
                /*清空弹出框内容*/
                function reset_display()
                {
                    if(isReload) {
                        window.location.reload();
                    }

                    $("#addIndex").val("");
                    $("#title").val("");
                    $("#messageID").val("");
					$("#categoryID").val("");
					$("#regiontext").val("");
					$("#intro").val("");
					$("#people").val("0");
                    $(":radio[name='isSend']").each(function(){$(this).closest('label').removeClass('active')});
                    um.setContent("");
                }

                /* 上传主图 */
                upload_img_1(headImgUrl,'fileupload',function(data){
                    if(data.result > 0) {
                        $('#fileupload').attr('data-id',data.path);
                        $("#pic").attr("src", data.path);
                    } else {
                        swal("网络出错","","error");
                    }
                });/*第一个参数：上传图片的路径,第二个参数：file_input标签id,第三个参数：回调函数*/
                
                /* 上传主图2 */
                upload_img_1(headImgUrl,'fileupload2',function(data){
                    if(data.result > 0) {
                        $('#fileupload2').attr('data-id',data.path);
                        $("#pic2").attr("src", data.path);
                    } else {
                        swal("网络出错","","error");
                    }
                });/*第一个参数：上传图片的路径,第二个参数：file_input标签id,第三个参数：回调函数*/

            });
                        
        </script>
    </body>
</html>